package Games.PumpGame.Entities
{
	import Framework.BaseEntity;
	import Framework.BaseGui;
	import Games.PumpGame.GameEntityType;
	import Games.PumpGame.Gui.PriceCard;
	
	/**
	 * ...
	 * @author Menno
	 */
	public class PowerPlant extends BaseEntity
	{
		private var _priceList:Array // Array with Numbers
		
		public function PowerPlant(priceLabel:PriceCard) 
		{
			super(priceLabel);
			this.guiComponent = priceLabel;
			this.type = GameEntityType.POWERPLANT;
			
			priceList = new Array();
			firstPrice();
		}
		
		override public function update():void 
		{
			super.update();
			addPricesToGui();
		}
		
		public function updateCycle():void
		{
			generatePrice();
		}
		
		private function firstPrice():void
		{
			addToPriceList(Math.random());
			addToPriceList(Math.random());
			addToPriceList(Math.random());
			
			addPricesToGui();
		}		
		
		private function generatePrice():void
		{
			addToPriceList(Math.random());

			addPricesToGui();
		}
		
		private function addPricesToGui():void
		{
 			(guiComponent as PriceCard).price = priceList;
			guiComponent.draw();
		}
		
		private function addToPriceList(value:Number):void
		{
			if (priceList.length >= 3)
			{
				priceList.shift()
			}
			
			priceList.push(value.toFixed(2));
		}
		
		public function get priceList():Array 
		{
			return _priceList;
		}
		
		public function set priceList(value:Array):void 
		{
			_priceList = value;
		}
	}
	
}